package com.ymatou.iapi.fundstrategy.testcase;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.fundstrategy.parameter.FundStrategy;
import com.ymatou.iapi.fundstrategy.parameter.FundStrategyCreateBean;
import com.ymatou.iapi.fundstrategy.parameter.FundStrategyinfo;
import com.ymatou.iapi.fundstrategy.parameter.YmtFundDimensiongetDimensionid;
import com.ymatou.iapi.fundstrategy.service.FundStrategyCreateCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.database.model.YmtFundStrategy;
import com.ymttest.database.model.YmtFundStrategyDimension;
import com.ymttest.database.sqlwapper.YmtFundDimensionWapper;
import com.ymttest.database.sqlwapper.YmtFundStrategyDimensionWapper;
import com.ymttest.database.sqlwapper.YmtFundStrategyWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

/**
 * 创建资金策略信息接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_FundStrategyCreate {
    private static FundStrategyCreateBean fundstrategycreateBean;
    private static FundStrategyCreateCall fundstrategycreateCall;
    private static YmtFundDimensiongetDimensionid ymtFundDDid;

    @BeforeClass
    public static void setUp() {
        Logger.createResultFile("创建资金策略接口");
    }

    @Before
    public void caseUp() {
        fundstrategycreateBean = new FundStrategyCreateBean();
        fundstrategycreateCall = new FundStrategyCreateCall();
        ymtFundDDid = new YmtFundDimensiongetDimensionid();
    }

    @AfterClass
    public static void tearDown() {
        Logger.generateResult(fundstrategycreateCall.getOpurl());
    }

    public static void fundSgetreturnerrcode(String ecode, String eMsg) throws Exception {
        try {

            // 获取返回报文的数据
            String dataStr = fundstrategycreateCall.getReturnData();
            // 返回报文断言
            String strategyId = new JSONObject(dataStr).getString("StrategyId");
            Logger.verifyIsNull(strategyId, "StrategyId为空");
            String errCode = new JSONObject(dataStr).getString("ErrCode");
            Logger.verifyIsContains(ecode, errCode, "ErrCode");
            String errMsg = new JSONObject(dataStr).getString("ErrMsg");
            Logger.verifyIsContains(eMsg, errMsg, eMsg);
            String body = new JSONObject(dataStr).getString("Body");
            Logger.verifyIsNull(body, "Body为空");
            String requestUrl = new JSONObject(dataStr).getString("RequestUrl");
            Logger.verifyIsNull(requestUrl, "RequestUrl为空");
            String Success = new JSONObject(dataStr).getString("Success");
            Logger.verifyIsContains(false, Success, "\"Success\":false");

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @After
    public void caseDown() {
        Logger.end();
    }

    @Test
    @Category({P1.class})
    @TestCase
    public void Tc_FundStrategyCreate_001() {
        Logger.start(true, "创建资金策略信息(收佣策略)");
        try {
            // TODO 补全case代码


            String[] fundDimensionidformsql = ymtFundDDid.ymtFundDimensiongetDimensionid();
            FundStrategyCreateBean fundstrategycreateBean = FundStrategy.fundStrategyCreate(1, // 1为收佣策略
                    YMTDateUtil.getBeforeOrNextDay(-100),
                    1, // 1特殊策略 2全局策略
                    112233,
                    "自动化测试人员",
                    fundDimensionidformsql[0], // 商品类目维度的Dimensionid
                    fundDimensionidformsql[1], // 商品价格维度的Dimensionid
                    fundDimensionidformsql[2]); // 国家维度的Dimensionid

            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();

            // 获取返回报文的数据
            String dataStr = fundstrategycreateCall.getReturnData();
            // 返回报文断言
            Logger.verifyNotNull(dataStr, "返回报文非空");
            String Success = new JSONObject(dataStr).getString("Success");
            Logger.verifyIsContains(Success, true, "\"Success\":true");
            String errMsg = new JSONObject(dataStr).getString("ErrMsg");
            Logger.verifyIsNull(errMsg, "Msg等于空");

            if (errMsg == "null") {

                // 获取返回报文的strategyId值
                String strategyId = new JSONObject(dataStr).getString("StrategyId");
                Logger.verifyNotNull(strategyId, "断言strategyId非空");

                // SQL Ymt_FundStrategy ymtfp库
                YmtFundStrategyWapper ymtFundStrategyWapper = new YmtFundStrategyWapper();
                List<YmtFundStrategy> strategyIdlist = ymtFundStrategyWapper.selectstrategy(strategyId);
                YmtFundStrategy ymtFundStrategy = strategyIdlist.get(0);
                // 断言
                String stid = ymtFundStrategy.getStrategyId();
                Logger.verifyEquals(strategyId, stid, "策略id");
                int strategyType = ymtFundStrategy.getStrategyType();
                Logger.verifyEquals(1, strategyType, "策略类型");
                BigDecimal strategyAmount = ymtFundStrategy.getStrategyAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyAmount, "佣金费率");
                BigDecimal strategyMaxAmount = ymtFundStrategy.getStrategyMaxAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyMaxAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyMaxAmount, "策略费用上限");
                BigDecimal strategyMinAmount = ymtFundStrategy.getStrategyMinAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyMinAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyMinAmount, "策略费用下限");
                BigDecimal strategyWeight = ymtFundStrategy.getStrategyWeight();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyWeight()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyWeight, "策略权重 ");
                int strategyLevelType = ymtFundStrategy.getStrategyLevelType();
                Logger.verifyEquals(1, strategyLevelType, "策略等级");
                int strategyStatus = ymtFundStrategy.getStrategyStatus();
                Logger.verifyEquals(1, strategyStatus, "策略状态");

                // SQL Ymt_FundStrategyDimension ymtfp库
                YmtFundStrategyDimensionWapper ymtFundStrategyDimensionWapper = new YmtFundStrategyDimensionWapper();
                List<YmtFundStrategyDimension> strategyDimensionlist =
                        ymtFundStrategyDimensionWapper.selectstrategydimension(strategyId);
                // 商品类目对应创建的策略数据
                YmtFundStrategyDimension yfsdforCategory = strategyDimensionlist.get(0);
                // 国家对应创建的策略数据
                YmtFundStrategyDimension yfsdforCountry = strategyDimensionlist.get(1);
                // 商品价格对应创建的策略数据
                YmtFundStrategyDimension yfsdforRange = strategyDimensionlist.get(2);
                // 商品类目对应策略数据的断言
                String did1 = yfsdforCategory.getDimensionId();
                Logger.verifyEquals(fundDimensionidformsql[0], did1, "维度id");
                String categoryid = yfsdforCategory.getStrategyDimensionIdentityId();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                        .getStrategyDimensionIdentityId(), categoryid, "商品类目id");
                String categoryname = yfsdforCategory.getStrategyDimensionIdentityName();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                        .getStrategyDimensionIdentityName(), categoryname, "商品类目名称");
                // 商品价格对应策略数据的断言
                String did2 = yfsdforRange.getDimensionId();
                Logger.verifyEquals(fundDimensionidformsql[1], did2, "维度id");
                BigDecimal beginRange = yfsdforRange.getStrategyDimensionBeginRange();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getStrategyDimensionBeginRange().setScale(2, BigDecimal.ROUND_HALF_UP), beginRange, "开始区间值");
                BigDecimal endRange = yfsdforRange.getStrategyDimensionEndRange();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getStrategyDimensionEndRange().setScale(2, BigDecimal.ROUND_HALF_UP), endRange, "结束区间值");
                boolean beginRangeInclude = yfsdforRange.getBeginRangeInclude();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getBeginRangeInclude(), beginRangeInclude, "是够包含开始区间");
                boolean endRangeInclude = yfsdforRange.getEndRangeInclude();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getEndRangeInclude(), endRangeInclude, "是够包含结束区间");
                // 国家对应策略数据的断言
                String did3 = yfsdforCountry.getDimensionId();
                Logger.verifyEquals(fundDimensionidformsql[2], did3, "国家id");
                String countryid = yfsdforCountry.getStrategyDimensionIdentityId();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(2)
                        .getStrategyDimensionIdentityId(), countryid, "国家id");
                String countryname = yfsdforCountry.getStrategyDimensionIdentityName();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(2)
                        .getStrategyDimensionIdentityName(), countryname, "国家名称");

            } else {
                throw new Exception(errMsg);
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FundStrategyCreate_002() {
        Logger.start(false, "资金策略信息不能为空");
        try {
            // TODO 补全case代码

            fundstrategycreateBean.setFundStrategy(null);

            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();

            // 返回报文断言
            fundSgetreturnerrcode("1023", "资金策略信息不能为空");


        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FundStrategyCreate_003() {
        Logger.start(false, "资金策略详情不能为空");
        try {
            // TODO 补全case代码

            // FundStrategy 第一层
            FundStrategyinfo fundStrategyinfo = new FundStrategyinfo();
            fundstrategycreateBean.setFundStrategy(fundStrategyinfo);
            // 第二层
            fundStrategyinfo.setStrategyType(1); // 策略类型
            fundStrategyinfo.setStrategyVaildBeginDate("2016-01-01");
            fundStrategyinfo.setStrategyVaildEndDate("2050-12-31");
            fundStrategyinfo.setStrategyStatus(1);
            fundStrategyinfo.setStrategyLevelType(1);
            fundStrategyinfo.setStrategyAmount(new BigDecimal(0.05));
            fundStrategyinfo.setStrategyMaxAmount(new BigDecimal(500));
            fundStrategyinfo.setStrategyMinAmount(new BigDecimal(20));
            fundStrategyinfo.setStrategyWeight(new BigDecimal(10));
            fundStrategyinfo.setUserId(112233);
            fundStrategyinfo.setUserLoginId("自动化测试人员");
            fundStrategyinfo.setStrategyDetailList(null);;

            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();

            // 返回报文断言
            fundSgetreturnerrcode("1024", "资金策略详情不能为空");


        } catch (Exception e) {
            Logger.fail(e);
        }
    }


    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FundStrategyCreate_004() {
        Logger.start(false, "策略开始生效日期不能为空");
        try {
            // TODO 补全case代码

            String[] fundDimensionidformsql = ymtFundDDid.ymtFundDimensiongetDimensionid();

            FundStrategyCreateBean fundstrategycreateBean = FundStrategy.fundStrategyCreate(1,
                    null, // 策略开始生效日期
                    1, // 1特殊策略 2全局策略
                    112233,
                    "自动化测试人员",
                    fundDimensionidformsql[0], // 商品类目维度的Dimensionid
                    fundDimensionidformsql[1], // 商品价格维度的Dimensionid
                    fundDimensionidformsql[2]); // 国家维度的Dimensionid


            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();

            // 返回报文断言
            fundSgetreturnerrcode("1041", "有效期开始时间不能为空");


        } catch (Exception e) {
            Logger.fail(e);
        }
    }


    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FundStrategyCreate_005() {
        Logger.start(false, "用户id不能为空");
        try {
            // TODO 补全case代码

            String[] fundDimensionidformsql = ymtFundDDid.ymtFundDimensiongetDimensionid();

            FundStrategyCreateBean fundstrategycreateBean = FundStrategy.fundStrategyCreate(1,
                    YMTDateUtil.getBeforeOrNextDay(-100),
                    1, // 1特殊策略 2全局策略
                    0,
                    "自动化测试人员",
                    fundDimensionidformsql[0], // 商品类目维度的Dimensionid
                    fundDimensionidformsql[1], // 商品价格维度的Dimensionid
                    fundDimensionidformsql[2]); // 国家维度的Dimensionid

            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();

            // 返回报文断言
            fundSgetreturnerrcode("1006", "用户id不能为空");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FundStrategyCreate_006() {
        Logger.start(false, "用户名不能为空");
        try {
            // TODO 补全case代码

            String[] fundDimensionidformsql = ymtFundDDid.ymtFundDimensiongetDimensionid();

            FundStrategyCreateBean fundstrategycreateBean = FundStrategy.fundStrategyCreate(1,
                    YMTDateUtil.getBeforeOrNextDay(-100),
                    1, // 1特殊策略 2全局策略
                    112233,
                    null,
                    fundDimensionidformsql[0], // 商品类目维度的Dimensionid
                    fundDimensionidformsql[1], // 商品价格维度的Dimensionid
                    fundDimensionidformsql[2]); // 国家维度的Dimensionid

            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();

            // 返回报文断言
            fundSgetreturnerrcode("1008", "用户名不能为空");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P2.class})
    @TestCase
    public void Tc_FundStrategyCreate_007() {
        Logger.start(false, "维度Id不能为空");
        try {
            // TODO 补全case代码

            FundStrategyCreateBean fundstrategycreateBean = FundStrategy.fundStrategyCreate(1,
                    YMTDateUtil.getBeforeOrNextDay(-100),
                    1, // 1特殊策略 2全局策略
                    112233,
                    "自动化测试人员",
                    "",
                    "",
                    "");

            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();

            // 返回报文断言
            fundSgetreturnerrcode("1043", "策略中相关维度id不能为空");


        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P3.class})
    @TestCase
    public void Tc_FundStrategyCreate_008() {
        Logger.start(true, "创建资金策略信息(退佣策略)");
        try {
            // TODO 补全case代码


            String[] fundDimensionidformsql = ymtFundDDid.ymtFundDimensiongetDimensionid();
            FundStrategyCreateBean fundstrategycreateBean = FundStrategy.fundStrategyCreate(2, // 1为收佣策略
                                                                                               // 2退佣策略
                                                                                               // 3返佣策略
                    YMTDateUtil.getBeforeOrNextDay(-100),
                    1, // 1特殊策略 2全局策略
                    112233,
                    "自动化测试人员",
                    fundDimensionidformsql[0], // 商品类目维度的Dimensionid
                    fundDimensionidformsql[1], // 商品价格维度的Dimensionid
                    fundDimensionidformsql[2]); // 国家维度的Dimensionid

            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();


            // 获取返回报文的数据
            String dataStr = fundstrategycreateCall.getReturnData();
            // 返回报文断言
            String Success = new JSONObject(dataStr).getString("Success");
            Logger.verifyIsContains(Success, true, "\"Success\":true");
            String errMsg = new JSONObject(dataStr).getString("ErrMsg");
            Logger.verifyIsNull(errMsg, "Msg等于空");

            if (errMsg == "null") {

                // 获取返回报文的strategyId值
                String strategyId = new JSONObject(dataStr).getString("StrategyId");
                Logger.verifyNotNull(strategyId, "断言strategyId非空");

                // SQL Ymt_FundStrategy ymtfp库
                YmtFundStrategyWapper ymtFundStrategyWapper = new YmtFundStrategyWapper();
                List<YmtFundStrategy> strategyIdlist = ymtFundStrategyWapper.selectstrategy(strategyId);
                YmtFundStrategy ymtFundStrategy = strategyIdlist.get(0);
                // 断言
                String stid = ymtFundStrategy.getStrategyId();
                Logger.verifyEquals(strategyId, stid, "策略id");
                int strategyType = ymtFundStrategy.getStrategyType();
                Logger.verifyEquals(2, strategyType, "策略类型");
                BigDecimal strategyAmount = ymtFundStrategy.getStrategyAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyAmount, "佣金费率");
                BigDecimal strategyMaxAmount = ymtFundStrategy.getStrategyMaxAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyMaxAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyMaxAmount, "策略费用上限");
                BigDecimal strategyMinAmount = ymtFundStrategy.getStrategyMinAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyMinAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyMinAmount, "策略费用下限");
                BigDecimal strategyWeight = ymtFundStrategy.getStrategyWeight();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyWeight()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyWeight, "策略权重 ");
                int strategyLevelType = ymtFundStrategy.getStrategyLevelType();
                Logger.verifyEquals(1, strategyLevelType, "策略等级");
                int strategyStatus = ymtFundStrategy.getStrategyStatus();
                Logger.verifyEquals(1, strategyStatus, "策略状态");

                // SQL Ymt_FundStrategyDimension ymtfp库
                YmtFundStrategyDimensionWapper ymtFundStrategyDimensionWapper = new YmtFundStrategyDimensionWapper();
                List<YmtFundStrategyDimension> strategyDimensionlist =
                        ymtFundStrategyDimensionWapper.selectstrategydimension(strategyId);
                // 商品类目对应创建的策略数据
                YmtFundStrategyDimension yfsdforCategory = strategyDimensionlist.get(0);
                // 国家对应创建的策略数据
                YmtFundStrategyDimension yfsdforCountry = strategyDimensionlist.get(1);
                // 商品价格对应创建的策略数据
                YmtFundStrategyDimension yfsdforRange = strategyDimensionlist.get(2);
                // 商品类目对应策略数据的断言
                String did1 = yfsdforCategory.getDimensionId();
                Logger.verifyEquals(fundDimensionidformsql[0], did1, "商品类目维度id");
                String categoryid = yfsdforCategory.getStrategyDimensionIdentityId();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                        .getStrategyDimensionIdentityId(), categoryid, "商品类目id");
                String categoryname = yfsdforCategory.getStrategyDimensionIdentityName();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                        .getStrategyDimensionIdentityName(), categoryname, "商品类目名称");
                // 商品价格对应策略数据的断言
                String did2 = yfsdforRange.getDimensionId();
                Logger.verifyEquals(fundDimensionidformsql[1], did2, "商品价格维度id");
                BigDecimal beginRange = yfsdforRange.getStrategyDimensionBeginRange();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getStrategyDimensionBeginRange().setScale(2, BigDecimal.ROUND_HALF_UP), beginRange, "开始区间值");
                BigDecimal endRange = yfsdforRange.getStrategyDimensionEndRange();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getStrategyDimensionEndRange().setScale(2, BigDecimal.ROUND_HALF_UP), endRange, "结束区间值");
                boolean beginRangeInclude = yfsdforRange.getBeginRangeInclude();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getBeginRangeInclude(), beginRangeInclude, "是够包含开始区间");
                boolean endRangeInclude = yfsdforRange.getEndRangeInclude();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getEndRangeInclude(), endRangeInclude, "是够包含结束区间");
                // 国家对应策略数据的断言
                String did3 = yfsdforCountry.getDimensionId();
                Logger.verifyEquals(fundDimensionidformsql[2], did3, "国家id");
                String countryid = yfsdforCountry.getStrategyDimensionIdentityId();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(2)
                        .getStrategyDimensionIdentityId(), countryid, "国家id");
                String countryname = yfsdforCountry.getStrategyDimensionIdentityName();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(2)
                        .getStrategyDimensionIdentityName(), countryname, "国家名称");



            } else {
                throw new Exception(errMsg);
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P3.class})
    @TestCase
    public void Tc_FundStrategyCreate_009() {
        Logger.start(true, "创建资金策略信息(返佣策略)");
        try {
            // TODO 补全case代码

            String[] fundDimensionidformsql = ymtFundDDid.ymtFundDimensiongetDimensionid();
            FundStrategyCreateBean fundstrategycreateBean = FundStrategy.fundStrategyCreate(3, // 1为收佣策略
                                                                                               // 2退佣策略
                                                                                               // 3返佣策略
                    YMTDateUtil.getBeforeOrNextDay(-100),
                    1, // 1特殊策略 2全局策略
                    112233,
                    "自动化测试人员",
                    fundDimensionidformsql[0], // 商品类目维度的Dimensionid
                    fundDimensionidformsql[1], // 商品价格维度的Dimensionid
                    fundDimensionidformsql[2]); // 国家维度的Dimensionid

            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();

            // 获取返回报文的数据
            String dataStr = fundstrategycreateCall.getReturnData();
            // 返回报文断言
            String Success = new JSONObject(dataStr).getString("Success");
            Logger.verifyIsContains(Success, true, "\"Success\":true");
            String errMsg = new JSONObject(dataStr).getString("ErrMsg");
            Logger.verifyIsNull(errMsg, "Msg等于空");

            if (errMsg == "null") {

                // 获取返回报文的strategyId值
                String strategyId = new JSONObject(dataStr).getString("StrategyId");
                Logger.verifyNotNull(strategyId, "断言strategyId非空");

                // SQL Ymt_FundStrategy ymtfp库
                YmtFundStrategyWapper ymtFundStrategyWapper = new YmtFundStrategyWapper();
                List<YmtFundStrategy> strategyIdlist = ymtFundStrategyWapper.selectstrategy(strategyId);
                YmtFundStrategy ymtFundStrategy = strategyIdlist.get(0);
                // 断言
                String stid = ymtFundStrategy.getStrategyId();
                Logger.verifyEquals(strategyId, stid, "策略id");
                int strategyType = ymtFundStrategy.getStrategyType();
                Logger.verifyEquals(3, strategyType, "策略类型");
                BigDecimal strategyAmount = ymtFundStrategy.getStrategyAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyAmount, "佣金费率");
                BigDecimal strategyMaxAmount = ymtFundStrategy.getStrategyMaxAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyMaxAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyMaxAmount, "策略费用上限");
                BigDecimal strategyMinAmount = ymtFundStrategy.getStrategyMinAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyMinAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyMinAmount, "策略费用下限");
                BigDecimal strategyWeight = ymtFundStrategy.getStrategyWeight();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyWeight()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyWeight, "策略权重 ");
                int strategyLevelType = ymtFundStrategy.getStrategyLevelType();
                Logger.verifyEquals(1, strategyLevelType, "策略等级");
                int strategyStatus = ymtFundStrategy.getStrategyStatus();
                Logger.verifyEquals(1, strategyStatus, "策略状态");

                // SQL Ymt_FundStrategyDimension ymtfp库
                YmtFundStrategyDimensionWapper ymtFundStrategyDimensionWapper = new YmtFundStrategyDimensionWapper();
                List<YmtFundStrategyDimension> strategyDimensionlist =
                        ymtFundStrategyDimensionWapper.selectstrategydimension(strategyId);
                // 商品类目对应创建的策略数据
                YmtFundStrategyDimension yfsdforCategory = strategyDimensionlist.get(0);
                // 国家对应创建的策略数据
                YmtFundStrategyDimension yfsdforCountry = strategyDimensionlist.get(1);
                // 商品价格对应创建的策略数据
                YmtFundStrategyDimension yfsdforRange = strategyDimensionlist.get(2);
                // 商品类目对应策略数据的断言
                String did1 = yfsdforCategory.getDimensionId();
                Logger.verifyEquals(fundDimensionidformsql[0], did1, "商品类目维度id");
                String categoryid = yfsdforCategory.getStrategyDimensionIdentityId();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                        .getStrategyDimensionIdentityId(), categoryid, "商品类目id");
                String categoryname = yfsdforCategory.getStrategyDimensionIdentityName();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                        .getStrategyDimensionIdentityName(), categoryname, "商品类目名称");
                // 商品价格对应策略数据的断言
                String did2 = yfsdforRange.getDimensionId();
                Logger.verifyEquals(fundDimensionidformsql[1], did2, "商品价格维度id");
                BigDecimal beginRange = yfsdforRange.getStrategyDimensionBeginRange();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getStrategyDimensionBeginRange().setScale(2, BigDecimal.ROUND_HALF_UP), beginRange, "开始区间值");
                BigDecimal endRange = yfsdforRange.getStrategyDimensionEndRange();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getStrategyDimensionEndRange().setScale(2, BigDecimal.ROUND_HALF_UP), endRange, "结束区间值");
                boolean beginRangeInclude = yfsdforRange.getBeginRangeInclude();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getBeginRangeInclude(), beginRangeInclude, "是够包含开始区间");
                boolean endRangeInclude = yfsdforRange.getEndRangeInclude();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getEndRangeInclude(), endRangeInclude, "是够包含结束区间");
                // 国家对应策略数据的断言
                String did3 = yfsdforCountry.getDimensionId();
                Logger.verifyEquals(fundDimensionidformsql[2], did3, "国家id");
                String countryid = yfsdforCountry.getStrategyDimensionIdentityId();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(2)
                        .getStrategyDimensionIdentityId(), countryid, "国家id");
                String countryname = yfsdforCountry.getStrategyDimensionIdentityName();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(2)
                        .getStrategyDimensionIdentityName(), countryname, "国家名称");

            } else {
                throw new Exception(errMsg);
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P3.class})
    @TestCase
    public void Tc_FundStrategyCreate_010() {
        Logger.start(true, "创建没有国家维度的收佣策略");
        try {
            // TODO 补全case代码

            String[] fundDimensionidformsql = ymtFundDDid.ymtFundDimensiongetDimensionid();
            FundStrategyCreateBean fundstrategycreateBean = FundStrategy.fundStrategyCreate(1, // 1为收佣策略
                    YMTDateUtil.getBeforeOrNextDay(-100),
                    1, // 1特殊策略 2全局策略
                    112233,
                    "自动化测试人员",
                    fundDimensionidformsql[0], // 商品类目维度的Dimensionid
                    fundDimensionidformsql[1], // 价格区间维度的Dimensionid
                    null); // 国家维度的Dimensionid

            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();

            // 获取返回报文的数据
            String dataStr = fundstrategycreateCall.getReturnData();
            // 返回报文断言
            Logger.verifyNotNull(dataStr, "返回报文非空");
            String Success = new JSONObject(dataStr).getString("Success");
            Logger.verifyIsContains(Success, true, "\"Success\":true");
            String errMsg = new JSONObject(dataStr).getString("ErrMsg");
            Logger.verifyIsNull(errMsg, "Msg等于空");

            if (errMsg == "null") {

                // 获取返回报文的strategyId值
                String strategyId = new JSONObject(dataStr).getString("StrategyId");
                Logger.verifyNotNull(strategyId, "断言strategyId非空");

                // SQL Ymt_FundStrategy ymtfp库
                YmtFundStrategyWapper ymtFundStrategyWapper = new YmtFundStrategyWapper();
                List<YmtFundStrategy> strategyIdlist = ymtFundStrategyWapper.selectstrategy(strategyId);
                YmtFundStrategy ymtFundStrategy = strategyIdlist.get(0);
                // 断言
                String stid = ymtFundStrategy.getStrategyId();
                Logger.verifyEquals(strategyId, stid, "策略id");
                int strategyType = ymtFundStrategy.getStrategyType();
                Logger.verifyEquals(1, strategyType, "策略类型");
                BigDecimal strategyAmount = ymtFundStrategy.getStrategyAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyAmount, "佣金费率");
                BigDecimal strategyMaxAmount = ymtFundStrategy.getStrategyMaxAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyMaxAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyMaxAmount, "策略费用上限");
                BigDecimal strategyMinAmount = ymtFundStrategy.getStrategyMinAmount();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyMinAmount()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyMinAmount, "策略费用下限");
                BigDecimal strategyWeight = ymtFundStrategy.getStrategyWeight();
                Logger.verifyEquals(
                        fundstrategycreateBean.getFundStrategy().getStrategyWeight()
                                .setScale(2, BigDecimal.ROUND_HALF_UP), strategyWeight, "策略权重 ");
                int strategyLevelType = ymtFundStrategy.getStrategyLevelType();
                Logger.verifyEquals(1, strategyLevelType, "策略等级");
                int strategyStatus = ymtFundStrategy.getStrategyStatus();
                Logger.verifyEquals(1, strategyStatus, "策略状态");

                // SQL Ymt_FundStrategyDimension ymtfp库
                YmtFundStrategyDimensionWapper ymtFundStrategyDimensionWapper = new YmtFundStrategyDimensionWapper();
                List<YmtFundStrategyDimension> strategyDimensionlist =
                        ymtFundStrategyDimensionWapper.selectstrategydimension(strategyId);
                // 商品类目对应创建的策略数据
                YmtFundStrategyDimension yfsdforCategory = strategyDimensionlist.get(0);
                // 商品价格对应创建的策略数据
                YmtFundStrategyDimension yfsdforRange = strategyDimensionlist.get(1);
                // 商品类目对应策略数据的断言
                String did1 = yfsdforCategory.getDimensionId();
                Logger.verifyEquals(fundDimensionidformsql[0], did1, "维度id");
                String categoryid = yfsdforCategory.getStrategyDimensionIdentityId();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                        .getStrategyDimensionIdentityId(), categoryid, "商品类目id");
                String categoryname = yfsdforCategory.getStrategyDimensionIdentityName();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                        .getStrategyDimensionIdentityName(), categoryname, "商品类目名称");
                // 商品价格对应策略数据的断言
                String did2 = yfsdforRange.getDimensionId();
                Logger.verifyEquals(fundDimensionidformsql[1], did2, "维度id");
                BigDecimal beginRange = yfsdforRange.getStrategyDimensionBeginRange();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getStrategyDimensionBeginRange().setScale(2, BigDecimal.ROUND_HALF_UP), beginRange, "开始区间值");
                BigDecimal endRange = yfsdforRange.getStrategyDimensionEndRange();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getStrategyDimensionEndRange().setScale(2, BigDecimal.ROUND_HALF_UP), endRange, "结束区间值");
                boolean beginRangeInclude = yfsdforRange.getBeginRangeInclude();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getBeginRangeInclude(), beginRangeInclude, "是够包含开始区间");
                boolean endRangeInclude = yfsdforRange.getEndRangeInclude();
                Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(1)
                        .getEndRangeInclude(), endRangeInclude, "是够包含结束区间");

            } else {
                throw new Exception(errMsg);
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P3.class})
    @TestCase
    public void Tc_FundStrategyCreate_011() {
        Logger.start(true, "先创建一条没有国家维度的策略，再创建一条有国家维度且其他维度跟前一条相同的策略");
        try {
            // TODO 补全case代码
            String[] fundDimensionidformsql = ymtFundDDid.ymtFundDimensiongetDimensionid();
            String identityId = Integer.toString(TestDataManager.uniform(200000000));
            String beginDate = YMTDateUtil.getBeforeOrNextDay(-100);
            BigDecimal beginRange = new BigDecimal(TestDataManager.uniform(100)).add(new BigDecimal(2));
            BigDecimal endRange = new BigDecimal(TestDataManager.uniform(1000)).add(new BigDecimal(102));
            // 1.创建一条没有国家维度的策略
            FundStrategyCreateBean fundstrategycreateBean = FundStrategy.fundStrategyCreatefornoCountry(beginDate,
                    1, // 1特殊策略 2全局策略
                    fundDimensionidformsql[0], // 商品类目维度的Dimensionid
                    fundDimensionidformsql[1], // 价格区间维度的Dimensionid
                    null, // 国家维度的Dimensionid
                    beginRange, // 策略开始区间
                    endRange, // 策略结束区间
                    identityId); // 策略维度主体标识Id(国家id或者类目id)

            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();
            // 获取返回报文的数据
            String dataStr1 = fundstrategycreateCall.getReturnData();
            // 返回报文断言
            Logger.verifyNotNull(dataStr1, "返回报文非空");
            String Success1 = new JSONObject(dataStr1).getString("Success");
            Logger.verifyIsContains(Success1, true, "\"Success\":true");
            String errMsg1 = new JSONObject(dataStr1).getString("ErrMsg");
            Logger.verifyIsNull(errMsg1, "Msg等于空");
            // 获取返回报文的strategyId值
            String strategyId1 = new JSONObject(dataStr1).getString("StrategyId");
            Logger.verifyNotNull(strategyId1, "断言strategyId非空");

            // 2.创建一条有国家维度且其他维度跟前一条相同的策略
            FundStrategyCreateBean fundstrategycreateBean2 = FundStrategy.fundStrategyCreatefornoCountry(beginDate,
                    1, // 1特殊策略 2全局策略
                    fundDimensionidformsql[0], // 商品类目维度的Dimensionid
                    fundDimensionidformsql[1], // 价格区间维度的Dimensionid
                    fundDimensionidformsql[2], // 国家维度的Dimensionid
                    beginRange, // 策略开始区间
                    endRange, // 策略结束区间
                    identityId); // 策略维度主体标识Id(国家id或者类目id)
            fundstrategycreateCall.setData(fundstrategycreateBean2);
            fundstrategycreateCall.callService();
            // 获取返回报文的数据
            String dataStr2 = fundstrategycreateCall.getReturnData();
            // 返回报文断言
            Logger.verifyNotNull(dataStr2, "返回报文非空");
            String Success2 = new JSONObject(dataStr2).getString("Success");
            Logger.verifyIsContains(Success2, true, "\"Success\":true");
            String errMsg2 = new JSONObject(dataStr2).getString("ErrMsg");
            Logger.verifyIsNull(errMsg2, "Msg等于空");
            // 获取返回报文的strategyId值
            String strategyId2 = new JSONObject(dataStr2).getString("StrategyId");
            Logger.verifyNotNull(strategyId2, "断言strategyId非空");

            Logger.verifyNotEquals(strategyId1, strategyId2, "strategyId不相等");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P3.class})
    @TestCase
    public void Tc_FundStrategyCreate_012() {
        Logger.start(true, "创建全局策略");
        try {
            // TODO 补全case代码
            String identityId = Integer.toString(TestDataManager.uniform(200000000));
            String beginDate = YMTDateUtil.getBeforeOrNextSecond(500);
            BigDecimal beginRange12 = new BigDecimal(2000000004);
            BigDecimal endRange12 = new BigDecimal(2000000005);
            // 查询出已存在的全局策略的策略id
            YmtFundDimensionWapper ymtFundDimensionWapper = new YmtFundDimensionWapper();
            List<Map> rm = ymtFundDimensionWapper.selectstrategyidforhighleveltype(beginRange12);
            if (rm.size() > 0) {
                String stId12 = (String) rm.get(0).get("StrategyId");
                // 如果策略存在，更新状态为-1
                ymtFundDimensionWapper.updateStrategyStatusByStrategyId(stId12);
            }
            // 重新创建一条全局策略
            String[] fundDimensionidformsql = ymtFundDDid.ymtFundDimensiongetDimensionid();
            FundStrategyCreateBean fundstrategycreateBean = FundStrategy.fundStrategyCreatefornoCountry(beginDate,
                    2, // 1特殊策略 2全局策略
                    null, // 商品类目维度的Dimensionid
                    fundDimensionidformsql[1], // 价格区间维度的Dimensionid
                    null, // 国家维度的Dimensionid
                    beginRange12, // 策略开始区间
                    endRange12, // 策略结束区间
                    identityId); // 策略维度主体标识Id(国家id或者类目id)

            fundstrategycreateCall.setData(fundstrategycreateBean);
            fundstrategycreateCall.callService();
            // 获取返回报文的数据
            String dataStr = fundstrategycreateCall.getReturnData();
            // 返回报文断言
            Logger.verifyNotNull(dataStr, "返回报文非空");
            String Success = new JSONObject(dataStr).getString("Success");
            Logger.verifyIsContains(Success, true, "\"Success\":true");
            String errMsg = new JSONObject(dataStr).getString("ErrMsg");
            Logger.verifyIsNull(errMsg, "Msg等于空");
            // 获取返回报文的strategyId值
            String strategyId = new JSONObject(dataStr).getString("StrategyId");
            Logger.verifyNotNull(strategyId, "断言strategyId非空");

            // SQL Ymt_FundStrategy ymtfp库
            YmtFundStrategyWapper ymtFundStrategyWapper = new YmtFundStrategyWapper();
            List<YmtFundStrategy> strategyIdlist = ymtFundStrategyWapper.selectstrategy(strategyId);
            YmtFundStrategy ymtFundStrategy = strategyIdlist.get(0);
            // 断言
            String stid = ymtFundStrategy.getStrategyId();
            Logger.verifyEquals(strategyId, stid, "策略id");
            int strategyType = ymtFundStrategy.getStrategyType();
            Logger.verifyEquals(1, strategyType, "策略类型");
            BigDecimal strategyAmount = ymtFundStrategy.getStrategyAmount();
            Logger.verifyEquals(
                    fundstrategycreateBean.getFundStrategy().getStrategyAmount().setScale(2, BigDecimal.ROUND_HALF_UP),
                    strategyAmount, "佣金费率");
            BigDecimal strategyMaxAmount = ymtFundStrategy.getStrategyMaxAmount();
            Logger.verifyEquals(
                    fundstrategycreateBean.getFundStrategy().getStrategyMaxAmount()
                            .setScale(2, BigDecimal.ROUND_HALF_UP), strategyMaxAmount, "策略费用上限");
            BigDecimal strategyMinAmount = ymtFundStrategy.getStrategyMinAmount();
            Logger.verifyEquals(
                    fundstrategycreateBean.getFundStrategy().getStrategyMinAmount()
                            .setScale(2, BigDecimal.ROUND_HALF_UP), strategyMinAmount, "策略费用下限");
            BigDecimal strategyWeight = ymtFundStrategy.getStrategyWeight();
            Logger.verifyEquals(
                    fundstrategycreateBean.getFundStrategy().getStrategyWeight().setScale(2, BigDecimal.ROUND_HALF_UP),
                    strategyWeight, "策略权重 ");
            int strategyLevelType = ymtFundStrategy.getStrategyLevelType();
            Logger.verifyEquals(2, strategyLevelType, "策略等级");
            int strategyStatus = ymtFundStrategy.getStrategyStatus();
            Logger.verifyEquals(1, strategyStatus, "策略状态");

            // SQL Ymt_FundStrategyDimension ymtfp库
            YmtFundStrategyDimensionWapper ymtFundStrategyDimensionWapper = new YmtFundStrategyDimensionWapper();
            List<YmtFundStrategyDimension> strategyDimensionlist =
                    ymtFundStrategyDimensionWapper.selectstrategydimension(strategyId);
            // 商品价格对应创建的策略数据
            YmtFundStrategyDimension yfsdforRange = strategyDimensionlist.get(0);
            // 商品价格对应策略数据的断言
            String did2 = yfsdforRange.getDimensionId();
            Logger.verifyEquals(fundDimensionidformsql[1], did2, "维度id");
            BigDecimal beginRange1 = yfsdforRange.getStrategyDimensionBeginRange();
            Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                    .getStrategyDimensionBeginRange().setScale(2, BigDecimal.ROUND_HALF_UP), beginRange1, "开始区间值");
            BigDecimal endRange1 = yfsdforRange.getStrategyDimensionEndRange();
            Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                    .getStrategyDimensionEndRange().setScale(2, BigDecimal.ROUND_HALF_UP), endRange1, "结束区间值");
            boolean beginRangeInclude = yfsdforRange.getBeginRangeInclude();
            Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                    .getBeginRangeInclude(), beginRangeInclude, "是够包含开始区间");
            boolean endRangeInclude = yfsdforRange.getEndRangeInclude();
            Logger.verifyEquals(fundstrategycreateBean.getFundStrategy().getStrategyDetailList().get(0)
                    .getEndRangeInclude(), endRangeInclude, "是够包含结束区间");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

}
